/**
 *
 */
Ext.define('vacake.view.UsersCollect', {
    extend: 'Ext.List',
    xtype: 'usersCollect',
    config: {
        items: [{
                docked: 'top',
                xtype: 'titlebar',
                title: '收藏夹',
                items: [{
                        text: '返回',
                        ui: 'action-back',
                        handler: function() {
                            Ext.Viewport.remove(this.up('usersCollect'), true);
                        }
                    }
                ]
            }
        ],
        store: 'UsersCollect',
        emptyText: '<div style="width: 100%; height: 100%; text-align: center; vertical-align: middle">' +
            '<img width="94" height="94" src="resources/images/null.png" style="margin-top:100px;"   /> ' +
            '<div class="height30 color2 font2">暂时没有收藏</div>' +
            '</div>',
        cls: 'x-list1',
        itemTpl: "<div style='height:80px; position: relative; width: 70%'>" +
            "<img  src='{picurl}' style='float: left;height: 80px;width: 80px' class='radius'/> " +
            "<div class='homelist_name height30 color2 font5'>{pname}</div>" +
            "<div class='homelist_name height30'><img src='resources/images/product_grade_{product.grade}.png' class='img97'></div>" +
            "<div class='homelist_name height20 font5'><span class='color3'>{[values.product.standards[0].name]}" +
            "<span class='color5' style='margin-left: 10px;'> " +
            "{[values.product.isviewbate==1?values.product.standards[0].reprice:values.product.standards[0].price]}￥" + "</span>" +
            "</span></div>" +
            "</div>",
        onItemDisclosure: { //点击小按钮的时候,触发的事件
            handler: function(record, btn, index, e) {
                e.stopEvent();
                Ext.Msg.confirm('是否删除？', '', function(data) {
                    if (data == 'yes') {
                        Ext.Viewport.mask({
                            xtype: 'loadmask',
                            message: '删除中...'
                        });
                        Ext.Ajax.request({
                            url: Global.api_url + '/cloud/1/collect_delete',
                            params: {
                                cucid: record.get('cucid'),
                                caid: Global.app_id
                            },
                            method: 'POST',
                            scope: this,
                            success: function(response) {
                                Ext.Viewport.unmask();
                                var returnText = Ext.decode(response.responseText);
                                cordova.exec(function(message) {}, function(error) {}, "Messages", "showMsg", [returnText.Variables.Message.messagestr]);
                                if (returnText.Variables.Result.code == 0) {
                                    var usersCollect = Ext.getStore('UsersCollect');
                                    usersCollect.load({
                                        params: {
                                            cuid: window.localStorage.getItem('app_Login_id'),
                                            cadid: window.localStorage.getItem('app_district_id')
                                        }
                                    });
                                }
                            },
                            failure: function() { //请求失败时执行操作
                                Ext.Viewport.unmask();
                                cordova.exec(function(message) {}, function(error) {}, "Messages", "showMsg", ['请求失败,服务器维护中...']);
                            }
                        })
                    }
                }, this);
            }
        },
        listeners: {
            painted: function() {
                var usersCollect = Ext.getStore('UsersCollect');
                usersCollect.load({
                    params: {
                        cuid: window.localStorage.getItem('app_Login_id'),
                        cadid: window.localStorage.getItem('app_district_id')
                    }
                });
                Ext.Viewport.unmask();
            },back: function () {
                var backid = Ext.Viewport.getInnerItems().length - 2;
                Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
                Ext.Viewport.setActiveItem(backid);
            }
        }
    }

});